package com.wd.live.module_login.view.fragment

import android.view.View
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.wd.live.module_base.net.bean.login.FindConstellationListBean
import com.wd.live.module_base.ui.base.BaseFragment
import com.wd.live.module_login.R
import com.wd.live.module_login.databinding.FragmentConstellationBinding
import com.wd.live.module_login.view.adapter.ConstellationAdapter
import com.wd.live.module_login.viewmodel.ReversoContextViewModel

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

class ConstellationFragment : BaseFragment<ReversoContextViewModel, FragmentConstellationBinding>() {
    private var labsConstellation= mutableListOf<FindConstellationListBean>()
    override fun initData() {
        //查询星座列表


//        viewModel.putModifyConstellation(101)
        val constellationAdapter =
            ConstellationAdapter(context, R.layout.constellation_item, viewModel.data)
        dataBinding.constellationRv.adapter=constellationAdapter
        dataBinding.constellationRv.layoutManager=GridLayoutManager(context,3)
        //接口回调返回到selectId 和判断他是否更改切换星座的状态
        constellationAdapter.setConstellationSet(object : ConstellationAdapter.ConstellationSet {
            override fun open(id: Int, flag: Boolean) {
                if (flag){
                    viewModel.putModifyConstellation(id)
                }
            }
        })
        viewModel.dataModifyConstellation.observe(this){
            Toast.makeText(context,it.message,Toast.LENGTH_SHORT).show()
        }
    }




    override fun getViewModelClass(): Class<ReversoContextViewModel> {
        return ReversoContextViewModel::class.java
    }

    override fun getLayout(): Int {
        return R.layout.fragment_constellation
    }

}